﻿requirejs.config({
    baseUrl: ".",
    paths: {
    	zepto:"javascripts/zepto.min",
    	dingtalk:"javascripts/dingtalk",
        vue: "components/vue/vue.min",
        axios: "components/axios/axios.min",
        MINT: "components/mint-ui/index",
        search: "resources/js/search",
        common: "resources/js/common"
    },
    shim: {
        "MINT": {
            deps: ["vue"],
            exports: "MINT"
        }
    }
});

require(["zepto","dingtalk","vue", "axios", "common", "MINT", "search"], function (zepto,dingtalk,Vue, axios, common, MINT, search) {

    Vue.component(MINT.Toast.name, MINT.Toast);

    var vm = new Vue({
        el: "#view",
        data: {
            data: {
                kngKnowledgeCategoryId: "",
                title: "",
                keyword: "",
                contents: "",
                accessRight: "companyLevel"
            },
            kngKnowledgeCategory: {
                id: "",
                name: ""
            },
            images: []
        },
        mounted: function () {
        },
        methods: {
            imgUpload: function (event) {
                common.imgUpload(event, this.images, MINT.Toast);
            },
            submit: function () {
                if (common.isEmpty(this.kngKnowledgeCategory.id)) {
                    MINT.Toast("请输入分类");
                    return;
                }
                if (common.isEmpty(this.data.title)) {
                    MINT.Toast("请输入标题");
                    return;
                }
                if (common.isEmpty(this.data.keyword)) {
                    MINT.Toast("请输入关键字");
                    return;
                }
                if (common.isEmpty(this.data.contents)) {
                    MINT.Toast("请输入内容");
                    return;
                }
                if (common.isEmpty(this.data.accessRight)) {
                    MINT.Toast("请输入权限");
                    return;
                }

                var data = {
                    data: this.data,
                    images: this.images
                };
                data.data.kngKnowledgeCategoryId = this.kngKnowledgeCategory.id

                axios.post("knowledge/new", data)
                    .then(function (response) {
                        window.location.href = "knowledgePublishSuccess.html";
                    });
            }
        }
    });
});